<template>
    <div>
        <div class="query">
            <span>姓名:</span><input @keydown.enter="search" v-model="patient.name" type="text" placeholder="请输入姓名">
            <span>手机号码:</span><input @keydown.enter="search" v-model="patient.phone" type="text" placeholder="请输入手机号码">
            <span>身份证号码:</span><input @keydown.enter="search" v-model="patient.card_id" type="text" placeholder="请输入身份证号">
            <button @click="search">查询</button>
            <button class="add" @click="add_patient">添加病人信息</button>
        </div>
    </div>
</template>

<script>

export default {
    name:'search',
    data(){
        return{
            patient:{
                name:'',
                phone:'',
                card_id:''
            },
        }
    },
    methods:{
        add_patient(){
            this.$emit("add_patient")
        },
        search(){
            // 判断对象是否为空
            // if(Object.keys(this.patient).length==0){
            //     this.$toast("请输入要查询的信息")
            //     return
            // }
            for(let item in this.patient){
                this.patient[item]=this.patient[item].trim()  //去除首尾空格
            }
            for (let item in this.patient){
                if(this.$my_tools.check_data[item] && this.patient[item]!=''){ 
                    let msg=this.$my_tools.check_data[item](this.patient[item])
                    if(msg){
                        this.$toast(msg)
                        return
                    }
                }
            }
            this.$emit("search",this.patient)
        }
    },
    mounted(){
        if(this.$store.state.global_var.search){
            this.patient=this.$store.state.global_var.search.patient
        }
    }
}
</script>

<style lang='scss' scoped>
    .query{
        display: flex;
        align-items: center;
        input{
            margin-right:5px;
            width: 200px;
        }
        input:nth-of-type(1){
            width: 100px;
        }
        input::placeholder{
            color:#aaa;
            font-size: 13px;
        }
        .add{
            margin-left:5px;
        }
    }
</style>